package com.zb.mobile.user.controller;

import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjFaultService;
import com.zb.service.ZjKnowledgeTypeFaultService;
import com.zb.service.ZjUserTypeKnowledgeTypeService;
import com.zb.utils.TokenUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author WEN
 * @Date 2023/11/15 0015
 **/
@Api(tags = "用户报单移动端故障库类接口")
@RestController
@RequestMapping("/mobile/user/fault")
public class UserFaultController {
    @Resource
    private ZjUserTypeKnowledgeTypeService userTypeKnowledgeTypeService;
    @Resource
    private ZjKnowledgeTypeFaultService knowledgeTypeFaultService;
    @Resource
    private ZjFaultService faultService;

    @ApiOperation("获取知识库分类列表")
    @PostMapping("/getUserMobileFaultList")
    public Result getUserMobileknowledgeTypeList(HttpServletRequest request, @RequestBody PageUtil pageUtil) {
        Long userId = TokenUserUtil.getAccountIdByToken(request);
        return Result.success().data(userTypeKnowledgeTypeService.getUserMobileknowledgeTypeList(userId, pageUtil));
    }

    @ApiOperation("根据知识库类型ID获取故障库列表")
    @PostMapping("/getUserMobileFaultList/{knowledgeTypeId}")
    public Result getUserMobileFaultList(@PathVariable @ApiParam(value = "知识库类型ID", required = true) Long knowledgeTypeId, @RequestBody PageUtil pageUtil) {
        return Result.success().data(knowledgeTypeFaultService.getUserMobileFaultList(knowledgeTypeId, pageUtil));
    }

    @ApiOperation("根据故障库ID获取故障详情内容")
    @GetMapping("/getUserMobileFaultDetail/{faultId}")
    public Result getUserMobileFaultDetail(@PathVariable @ApiParam(value = "故障库ID", required = true) Long faultId) {
        return Result.success().data(PageUtil.row(faultService.getUserMobileFaultDetail(faultId)));
    }

}
